package com.xiaobaibai.controller;

import com.xiaobaibai.common.response.ResponseFormat;
import com.xiaobaibai.pojo.Label;
import com.xiaobaibai.server.label.ILabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class LabelController {

    @Autowired
    private ILabelService labelService;

    @GetMapping("/getLabelList")
    public ResponseFormat getLabelList(){
        return ResponseFormat.createSuccessResponse("success",labelService.getLabelList());
    }

    @PostMapping("/addLabel")
    public ResponseFormat addLabel(@RequestParam("title") String title){
        Label label = labelService.addLabel(title);
        return ResponseFormat.createSuccessResponse("success",label);
    }

    @GetMapping("/delLabel")
    public ResponseFormat delLabel(@RequestParam("id")Integer id){

        boolean b = labelService.delLabel(id);
        if(!b)
            return ResponseFormat.createSuccessResponseOnlyMessage("error");
        return ResponseFormat.createSuccessResponseOnlyMessage("success");
    }

}
